<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style> 
        *{
            margin: 0;
            padding: 0;
        }
        .large {
            position: relative;
            padding-top: 50px;
            margin-left: 100px;
            width: 300px;
            height: 300px;
            background-color: orange;
            box-sizing: border-box;
        }
        .box {
            margin-top: 50px;
            margin-left: 50px;
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div class="large">
        <div class="box"></div>
    </div>
    
    <script>
        var box = document.querySelector('.box');
        //1.获取盒子顶部和左边的距离
        box.addEventListener('mousemove', function(event) {
            console.log(event.pageX);//获取鼠标相当于文档页面X坐标
            console.log(event.pageY);//获取鼠标相当于文档页面Y坐标
            console.log(box.offsetLeft);
            var x = event.pageX - this.offsetLeft;
            var y = event.pageY - this.offsetTop;
            box.innerHTML = 'x轴坐标：' + x + 'y轴坐标：' + y;
        })

    </script>
</body>
</html>